import { withUser, ApiError } from "@/lib/api"; import { exportArenaSession } from "@/lib/arena/service"; import { LIMITS } from "@/lib/rate-limit"; export const dynamic = "force-dynamic"; type P = { id: string }; /** POST /api/arena/:id/export?format=markdown|json → file download (models, parameters, metrics, votes, responses). */ export const POST = withUser

( async ({ req, user }, { id }) => { const format = new URL(req.url).searchParams.get("format") ?? "markdown"; if (format !== "markdown" && format !== "json" && format !== "md") throw new ApiError(400, "format must be markdown or json", "VALIDATION_ERROR"); const out = await exportArenaSession(user.id, id, format === "json" ? "json" : "markdown"); return new Response(out.body, { headers: { "Content-Type": out.contentType, "Content-Disposition": `attachment; filename="${out.filename}"`, "X-Filename": out.filename } }); }, { limit: { ...LIMITS.share, key: "arena-export" } }, );